//
//  Mine_WorkingViewController.m
//  fxxiaoke
//
//  Created by 鞠超 on 2016/12/8.
//  Copyright © 2016年 jc. All rights reserved.
//

#import "Mine_WorkingViewController.h"

#import "Mine_WorkingTableViewCell.h"

@interface Mine_WorkingViewController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView * tableView;
//
@property (nonatomic, strong) UIView * view_Head;
@property (nonatomic, strong) UIImageView * image_Head;
@property (nonatomic, strong) UILabel * lbl_name;
@property (nonatomic, strong) UILabel * lbl_department;

//
@property (nonatomic, strong) UIView * view_Wihte;
@property (nonatomic, strong) UIButton * btn_1;
@property (nonatomic, strong) UIButton * btn_2;
@property (nonatomic, strong) UIButton * btn_3;

@end

@implementation Mine_WorkingViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self p_navi];
    
    [self p_setupView];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

#pragma mark - navi
- (void )p_navi
{
    _btnLeft.hidden = YES;
    _lblLeft.hidden = YES;
    _btnRight.hidden = YES;
    _lblRight.hidden = YES;
    
    _lblTitle.text = @"个人信息";
    _topView.backgroundColor = navi_bar_bg_color;
    
    //左返回
    UIImageView * image_LeftRetrun = [[UIImageView alloc] initWithFrame:CGRectMake(11, 31.5, 25, 25)];
    image_LeftRetrun.userInteractionEnabled = YES;
    image_LeftRetrun.image = [UIImage imageNamed:@"Left-return.png"];
    [_topView addSubview:image_LeftRetrun];
    
    UILabel * lbl_return = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(image_LeftRetrun.frame) - 6, 35, 100, 15)];
    lbl_return.text = @"返回";
    lbl_return.textColor = [UIColor whiteColor];
    lbl_return.font = [UIFont systemFontOfSize:17];
    [_topView addSubview:lbl_return];
    
    UIButton * btn_return = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_return.frame = CGRectMake(10, 22, 100, 40);
    [_topView addSubview:btn_return];
    [btn_return addTarget:self action:@selector(btn_returnAction:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //搜索
    UIImageView * image_Setting = [[UIImageView alloc] initWithFrame:CGRectMake(SCREEN_WIDTH - 35, 32, 20, 20)];
    image_Setting.image = [UIImage imageNamed:@"Search_white.png"];
    [_topView addSubview:image_Setting];
    
    UIButton * btn_Setting = [UIButton buttonWithType:(UIButtonTypeSystem)];
    btn_Setting.frame = CGRectMake(SCREEN_WIDTH - 10 - 35, 24.5, 35, 35);
    [_topView addSubview:btn_Setting];
    [btn_Setting addTarget:self action:@selector(SettingAction:) forControlEvents:(UIControlEventTouchUpInside)];
}

//左返回
- (void )btn_returnAction:(UIButton *)sender
{
    [self.navigationController popViewControllerAnimated:YES];
}

//右侧搜索
- (void)SettingAction:(UIButton *)sender
{
    NSLog(@"点击搜索");
}

//显示tabbar
- (void )viewWillAppear:(BOOL)animated
{
    [(AppDelegate *)[[UIApplication sharedApplication] delegate] hiddenTabBar];
}

#pragma mark - 布局
- (void )p_setupView
{
    self.view.backgroundColor = [UIColor whiteColor];
    
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 64, SCREEN_WIDTH, SCREEN_HEIGHT - 64) style:(UITableViewStylePlain)];
    self.tableView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.tableFooterView = [[UIView alloc] init];
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    //
    [self p_headView];
    self.tableView.tableHeaderView = self.view_Head;
    [self.view addSubview:self.tableView];
    
    //注册
    [self.tableView registerClass:[Mine_WorkingTableViewCell class] forCellReuseIdentifier:@"cell_head"];
    [self.tableView registerClass:[UITableViewCell class] forCellReuseIdentifier:@"cell_middle"];
}

#pragma mark - tableview代理
- (NSInteger )numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 3;
}

- (CGFloat )tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 150.0f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if(indexPath.row == 0)
    {
        Mine_WorkingTableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_head" forIndexPath:indexPath];
        
        
        return cell;
    }
    else
    {
        UITableViewCell * cell = [tableView dequeueReusableCellWithIdentifier:@"cell_middle" forIndexPath:indexPath];
        
        return cell;
    }
}

#pragma mark - 头视图
- (void )p_headView
{
    self.view_Head = [[UIView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 155)];
    self.view_Head.backgroundColor = [UIColor groupTableViewBackgroundColor];
    
    //头部视图
    self.image_Head = [[UIImageView alloc] initWithFrame:CGRectMake(15, 15, 60, 60)];
    self.image_Head.layer.cornerRadius = 30;
    self.image_Head.image = [UIImage imageNamed:@"heads.jpg"];
    self.image_Head.layer.masksToBounds = YES;
    [self.view_Head addSubview:self.image_Head];
    
    //
    self.lbl_name = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_Head.frame) + 10, CGRectGetMinY(self.image_Head.frame) + 5, SCREEN_WIDTH - 15 - CGRectGetMaxX(self.image_Head.frame) - 10, 20)];
    self.lbl_name.text = @"员工名称";
    self.lbl_name.textColor = [UIColor blackColor];
    self.lbl_name.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Head addSubview:self.lbl_name];
    
    //
    self.lbl_department = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.image_Head.frame) + 10, CGRectGetMaxY(self.lbl_name.frame) + 10, SCREEN_WIDTH - 15 - CGRectGetMaxX(self.image_Head.frame) - 10, 20)];
    self.lbl_department.textColor = [UIColor grayColor];
    self.lbl_department.text = @"员工职位 - 部门名称";
    self.lbl_department.font = [UIFont systemFontOfSize:16.0f];
    [self.view_Head addSubview:self.lbl_department];
    
    //白色视图
    self.view_Wihte = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.image_Head.frame) + 10, SCREEN_WIDTH, 70)];
    self.view_Wihte.backgroundColor = [UIColor whiteColor];
    [self.view_Head addSubview:self.view_Wihte];
    
    UIView * view_Line = [[UIView alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(self.view_Wihte.frame), SCREEN_WIDTH, 0.5)];
    view_Line.backgroundColor = [UIColor grayColor];
    [self.view_Head addSubview:view_Line];
    
    CGFloat length_X = SCREEN_WIDTH / 3;
    
    //全部
    UILabel * lbl_All = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, length_X, 15)];
    lbl_All.text = @"全部";
    lbl_All.textColor = [UIColor grayColor];
    lbl_All.textAlignment = NSTextAlignmentCenter;
    lbl_All.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Wihte addSubview:lbl_All];
    
    UIImageView * image_arrowhead = [[UIImageView alloc] initWithFrame:CGRectMake(length_X / 2 - 10, 45, 20, 20)];
    image_arrowhead.image = [UIImage imageNamed:@"downward_Arrowhead.png"];
    image_arrowhead.layer.masksToBounds = YES;
    image_arrowhead.userInteractionEnabled = YES;
    [self.view_Wihte addSubview:image_arrowhead];
    
    UIView * view_Line1 = [[UIView alloc] initWithFrame:CGRectMake(length_X - 0.5, 20, 1, 35)];
    view_Line1.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view_Wihte addSubview:view_Line1];
    
    self.btn_1 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    self.btn_1.frame = CGRectMake(0, 0, length_X, 70);
    [self.view_Wihte addSubview:self.btn_1];
    [self.btn_1 addTarget:self action:@selector(btn_1Action:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //工作
    UILabel * lbl_work = [[UILabel alloc] initWithFrame:CGRectMake(length_X, 20, length_X, 15)];
    lbl_work.text = @"工作";
    lbl_work.textColor = [UIColor grayColor];
    lbl_work.textAlignment = NSTextAlignmentCenter;
    lbl_work.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Wihte addSubview:lbl_work];
    
    UILabel * lbl_reply = [[UILabel alloc] initWithFrame:CGRectMake(length_X, 40, length_X, 15)];
    lbl_reply.text = @"回复";
    lbl_reply.textColor = [UIColor grayColor];
    lbl_reply.textAlignment = NSTextAlignmentCenter;
    lbl_reply.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Wihte addSubview:lbl_reply];
    
    UIView * view_Line2 = [[UIView alloc] initWithFrame:CGRectMake(length_X * 2 - 0.5, 20, 1, 35)];
    view_Line2.backgroundColor = [UIColor groupTableViewBackgroundColor];
    [self.view_Wihte addSubview:view_Line2];
    
    self.btn_2 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    self.btn_2.frame = CGRectMake(length_X, 0, length_X, 70);
    [self.view_Wihte addSubview:self.btn_2];
    [self.btn_2 addTarget:self action:@selector(btn_2Action:) forControlEvents:(UIControlEventTouchUpInside)];
    
    //工作文档
    UILabel * lbl_work1 = [[UILabel alloc] initWithFrame:CGRectMake(length_X * 2, 20, length_X, 15)];
    lbl_work1.text = @"工作";
    lbl_work1.textColor = [UIColor grayColor];
    lbl_work1.textAlignment = NSTextAlignmentCenter;
    lbl_work1.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Wihte addSubview:lbl_work1];
    
    UILabel * lbl_text = [[UILabel alloc] initWithFrame:CGRectMake(length_X * 2, 40, length_X, 15)];
    lbl_text.text = @"文档";
    lbl_text.textColor = [UIColor grayColor];
    lbl_text.textAlignment = NSTextAlignmentCenter;
    lbl_text.font = [UIFont systemFontOfSize:17.0f];
    [self.view_Wihte addSubview:lbl_text];
    
    self.btn_3 = [UIButton buttonWithType:(UIButtonTypeSystem)];
    self.btn_3.frame = CGRectMake(length_X * 2, 0, length_X, 70);
    [self.view_Wihte addSubview:self.btn_3];
    [self.btn_3 addTarget:self action:@selector(btn_3Action:) forControlEvents:(UIControlEventTouchUpInside)];
}

#pragma mark - 点击事件
- (void )btn_1Action:(UIButton *)sender
{
    NSLog(@"点击全部");
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新tableView(记住,要更新放在主线程中)
        [self.tableView reloadData];
    });
}

- (void )btn_2Action:(UIButton *)sender
{
    NSLog(@"点击工作回复");
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新tableView(记住,要更新放在主线程中)
        [self.tableView reloadData];
    });
}

- (void )btn_3Action:(UIButton *)sender
{
    NSLog(@"点击工作文档");
    
    dispatch_async(dispatch_get_main_queue(), ^{
        //刷新tableView(记住,要更新放在主线程中)
        [self.tableView reloadData];
    });
}







@end
